class InitPos {
  constructor(imgSprite, scale = 1) {
    this._imgSprite = imgSprite;
    this._scale = scale;
  }

  get pos() {
    return {
      left: this.left,
      top: this.top,
      scale: this._scale
    }
  }

  set scale(scale) {
    this._scale = scale;
  }

  get scaleW() {
    const sprite = this._imgSprite;
    return sprite.canvasWidth / sprite.actualWidth;
  }

  get scaleH() {
    const sprite = this._imgSprite;
    return sprite.canvasHeight / sprite.actualHeight;
  }

  get left() {
    const left = (this._imgSprite.canvasWidth - this._imgSprite.actualWidth * this._scale) / 2;
    return left < 0 ? 0 : left;
  }

  get top() {
    const top = (this._imgSprite.canvasHeight - this._imgSprite.actualHeight * this._scale) / 2;
    return top < 0 ? 0 : top;
  }
}

/**
 * 宽高都小于canvas的宽高
 */
class SmallPos extends InitPos {

  get pos() {
    return super.pos;
  }
}

/**
 * 只有宽度大于canvas的宽度
 */
class WidthLargerPos extends InitPos {
  get pos() {
    this.scale = this.scaleW;
    return super.pos;
  }
}

/**
 * 只有高度大于canvas的高度
 */
class HeightLargerPos extends InitPos {
  get pos() {
    this.scale = this.scaleH;
    return super.pos;
  }
}

/**
 * 如果宽度和高度都大于canvas的宽高
 */
class BothLargerPos extends InitPos {
  get pos() {
    const scaleW = this.scaleW;
    const scaleH = this.scaleH;
    this.scale = scaleW > scaleH ? scaleH : scaleW;
    return super.pos;
  }
}
